<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Website extends CI_Controller {
	public function addsite(){
		$this->load->library('myclass');	
			
		$siteid = $this->input->post('siteid');
		$domain = $this->input->post('domain');
		$uid = $this->input->post('uid');
		$sitencrypt =  $this->myclass->randomkeys();
		$smtpserver = 'ssl://smtp.gmail.com';
		$smtpuser = $this->input->post('smtpuser');
		$smtppassword = $this->input->post('smtppassword');
		$ssl = 1;
		$status = $this->input->post('status');
		
		$data = array('siteid' => $siteid, 'sitename' => $domain, 'create_time' => time(), 'uid'=> $uid, 'sitencrypt'=>$sitencrypt, 'smtpserver'=>$smtpserver, 'smtpuser'=>$smtpuser, 'smtppassword'=>$smtppassword, 'ssl'=> $ssl, 'status'=>$status);
		
		$this->load->model('website_model');
		$this->website_model->insert_website($data);
		
		header("Location:/sdksystem/sitelist");exit;
	}
	
	public function currency(){
		$config[0]['currency'] = 'usd';
		$config[0]['symbol'] = '$';
		$config[0]['default_c'] = $this->input->post('default_c') == 'usd' ? 1 : 0;
		$config[0]['rate'] = 1;
		
		$config[1]['currency'] = 'gbp';
		$config[1]['symbol'] = '£';
		$config[1]['default_c'] = $this->input->post('default_c') == 'gbp' ? 1 : 0;
		$config[1]['rate'] =  (float)$this->input->post('rate_gbp');
		
		$config[2]['currency'] = 'eur';
		$config[2]['symbol'] = '€';
		$config[2]['default_c'] = $this->input->post('default_c') == 'eur' ? 1 : 0;
		$config[2]['rate'] = (float)$this->input->post('rate_eur');
		
		 $data = serialize(json_encode($config));
		 $siteid = $this->input->post('siteid');
		 
		 $this->load->model('currency_model', 'cm');
		 $this->cm->update_currency($config, $siteid);
		 
		 $this->load->model('website_model', 'wm');
		 $site = $this->wm->get_site_row($siteid);
		 
		 $url = 'http://www.' . $site->sitename . '/currency/icurrency';
		 
		 $this->load->library('myclass');
		 $r = $this->myclass->v_post($url, 'the_data=' . $data);
		 
		 if ($r == 1){
		 	echo '<script>alert("update success!");location.href="/sdksystem/sitelist";</script>';
		 }else{
		 	echo $r;
		 }
	}	
	
}